import router from '@system.router';
import prompt from '@system.prompt';
const app = getApp();

export default {
    data: {
        user: "",
        password: "",
        agreement: false
    },
    login() {
        if (this.agreement) {
            if (app.login(this.user, this.password)) {
                prompt.showToast({
                    message: "登陆成功",
                    duration: 2000
                });
                setTimeout(() => router.back(), 2000);

            } else {
                prompt.showToast({
                    message: "用户名或密码不正确",
                    duration: 2000
                });
            }
        } else {
            prompt.showDialog({
                title: "服务协议及隐私保护",
                message: "为了更好地保障您的合法权益，请您阅读并同意以下协议《淘宝平台服务协议》《隐私权政策》《支付宝注册相关协议》",
                buttons: [
                    {
                        text: "确定", color: "#000000"
                    },
                ]
            })
        }
    },

    goBack() {
        router.back();
    },
    goRegister() {
        router.push({
            uri: "pages/register/register"
        });
    },
    inputUser(message) {
        this.user = message.text;
    },
    inputPassword(message) {
        this.password = message.text;
    },
    checkAgreement() {
        this.agreement = !this.agreement;
    }
}
